﻿using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WatiN.Core;
using Expect.Core;
using System.Threading;

namespace Expect.WatiN.Sample.Pages
{
    [FixtureHint("When I am on Google home page")]
    public class WhenIAmOnGoogleHomePage : ExpectPage
    {
        [FindBy(Name = "q")]
        public TextField SearchCriteria;

        [FindBy(Name = "btnG")]
        public Button SearchButton;

        [FixtureHint("if I search for |*|")]
        public void IfISearchFor(string searchtoken)
        {
            SearchCriteria.TypeText(searchtoken);
            SearchButton.Click();
        }

        [FixtureHint("I must have a link to |*|")]
        public void IMustHaveALinkTo(string targeturl)
        {
            Thread.Sleep(400);
            var elt = Context.Browser().Span("search");
            elt.WaitUntilExists();
            Assert.IsTrue(elt.Links.Any(l => l.Url.StartsWith(targeturl)));
        }
    }
}
